/*
Copyright 2005-2014 CP Fricano - All Rights Reserved

This software and source code is licensed under the Apache
License, Version 2.0. You may not use this software or source
code except in compliance with the License.  You may obtain a
copy of the License at: http://www.apache.org/licenses/LICENSE-2.0.
Use and distributed under this License is on an "as is" basis,
without expressed or implied warranties or conditions of any kind.
See the License for the specific language governing permissions and
limitations.
 */

package com.fricano.java42.weather.api.provider.impl;

import java.util.List;
import java.util.Map;

import com.fricano.java42.base.components.datapointprovider.impl.ProviderConnector_JSON;
import com.fricano.java42.base.components.datapointprovider.impl.ProviderDataPointMap;
import com.fricano.java42.weather.api.provider.adapter.Key;
import com.fricano.java42.weather.api.provider.adapter.WeatherProviderInfo;

public class USGSEarthQuakeProviderInfo extends WeatherProviderInfo {

    public USGSEarthQuakeProviderInfo(final Object apiKey) {
        super(apiKey);
        super._query = "27613";
        super._dataPointMap.put(Key.LOCATION_FULL, new String[] { "features", "[properties]" });
    }

    @Override
    public ProviderDataPointMap<Object, Object> getDataPointMap() {
        return super._dataPointMap;
    }

    @Override
    protected String getDebugBody() {
        final String debugBody = "{\"bbox\":[-122.8215,33.1463333,1.89,-116.3708333,40.234,14.81],\"features\":[{\"id\":\"ci15510329\",\"properties\":{\"detail\":\"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/ci15510329.geojson\",\"type\":\"earthquake\",\"net\":\"ci\",\"tsunami\":null,\"sources\":\",ci,\",\"title\":\"M 1.1 - 12km NE of Julian, California\",\"time\":1402340155180,\"updated\":1402340413270,\"mag\":1.06,\"place\":\"12km NE of Julian, California\",\"types\":\",general-link,geoserve,nearby-cities,origin,phase-data,scitech-link,\",\"status\":\"automatic\",\"alert\":null,\"ids\":\",ci15510329,\",\"rms\":0.21,\"code\":\"15510329\",\"url\":\"http://earthquake.usgs.gov/earthquakes/eventpage/ci15510329\",\"magType\":\"ml\",\"mmi\":null,\"cdi\":null,\"tz\":-420,\"felt\":null,\"nst\":28,\"dmin\":0.1044,\"sig\":17,\"gap\":74},\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-116.5003333,33.1463333,9.67]}},{\"id\":\"nc72235046\",\"properties\":{\"detail\":\"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/nc72235046.geojson\",\"type\":\"earthquake\",\"net\":\"nc\",\"tsunami\":null,\"sources\":\",nc,\",\"title\":\"M 0.6 - 8km W of Cobb, California\",\"time\":1402340045200,\"updated\":1402340146004,\"mag\":0.6,\"place\":\"8km W of Cobb, California\",\"types\":\",general-link,geoserve,nearby-cities,origin,phase-data,\",\"status\":\"AUTOMATIC\",\"alert\":null,\"ids\":\",nc72235046,\",\"rms\":0.04,\"code\":\"72235046\",\"url\":\"http://earthquake.usgs.gov/earthquakes/eventpage/nc72235046\",\"magType\":\"Md\",\"mmi\":null,\"cdi\":null,\"tz\":-420,\"felt\":null,\"nst\":8,\"dmin\":0.00898315,\"sig\":6,\"gap\":140.4},\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-122.8215,38.8358,5]}},{\"id\":\"nn00448591\",\"properties\":{\"detail\":\"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/nn00448591.geojson\",\"type\":\"earthquake\",\"net\":\"nn\",\"tsunami\":null,\"sources\":\",nn,\",\"title\":\"M 1.7 - 15km ESE of Janesville, California\",\"time\":1402339637590,\"updated\":1402339726000,\"mag\":1.66,\"place\":\"15km ESE of Janesville, California\",\"types\":\",general-link,geoserve,nearby-cities,origin,phase-data,\",\"status\":\"automatic\",\"alert\":null,\"ids\":\",nn00448591,\",\"rms\":null,\"code\":\"00448591\",\"url\":\"http://earthquake.usgs.gov/earthquakes/eventpage/nn00448591\",\"magType\":\"ml\",\"mmi\":null,\"cdi\":null,\"tz\":-420,\"felt\":null,\"nst\":5,\"dmin\":0.641,\"sig\":42,\"gap\":291.55},\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-120.3675,40.234,1.89]}},{\"id\":\"ci15510321\",\"properties\":{\"detail\":\"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/ci15510321.geojson\",\"type\":\"earthquake\",\"net\":\"ci\",\"tsunami\":null,\"sources\":\",ci,\",\"title\":\"M 1.3 - 36km N of Yucca Valley, California\",\"time\":1402339516320,\"updated\":1402339764090,\"mag\":1.32,\"place\":\"36km N of Yucca Valley, California\",\"types\":\",general-link,geoserve,nearby-cities,origin,phase-data,scitech-link,\",\"status\":\"automatic\",\"alert\":null,\"ids\":\",ci15510321,\",\"rms\":0.24,\"code\":\"15510321\",\"url\":\"http://earthquake.usgs.gov/earthquakes/eventpage/ci15510321\",\"magType\":\"ml\",\"mmi\":null,\"cdi\":null,\"tz\":-420,\"felt\":null,\"nst\":24,\"dmin\":0.1185,\"sig\":27,\"gap\":70},\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-116.4955,34.4346667,7.95]}},{\"id\":\"ci15510313\",\"properties\":{\"detail\":\"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/ci15510313.geojson\",\"type\":\"earthquake\",\"net\":\"ci\",\"tsunami\":null,\"sources\":\",ci,\",\"title\":\"M 1.3 - 10km N of Borrego Springs, California\",\"time\":1402338985590,\"updated\":1402339646930,\"mag\":1.34,\"place\":\"10km N of Borrego Springs, California\",\"types\":\",focal-mechanism,general-link,geoserve,nearby-cities,origin,phase-data,scitech-link,\",\"status\":\"automatic\",\"alert\":null,\"ids\":\",ci15510313,\",\"rms\":0.22,\"code\":\"15510313\",\"url\":\"http://earthquake.usgs.gov/earthquakes/eventpage/ci15510313\",\"magType\":\"ml\",\"mmi\":null,\"cdi\":null,\"tz\":-420,\"felt\":null,\"nst\":30,\"dmin\":0.08988,\"sig\":28,\"gap\":116},\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-116.3708333,33.3495,14.81]}},{\"id\":\"nn00448588\",\"properties\":{\"detail\":\"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/nn00448588.geojson\",\"type\":\"earthquake\",\"net\":\"nn\",\"tsunami\":null,\"sources\":\",nn,\",\"title\":\"M 1.0 - 28km S of Hawthorne, Nevada\",\"time\":1402338908750,\"updated\":1402339110000,\"mag\":1.02,\"place\":\"28km S of Hawthorne, Nevada\",\"types\":\",general-link,geoserve,nearby-cities,origin,phase-data,\",\"status\":\"automatic\",\"alert\":null,\"ids\":\",nn00448588,\",\"rms\":null,\"code\":\"00448588\",\"url\":\"http://earthquake.usgs.gov/earthquakes/eventpage/nn00448588\",\"magType\":\"ml\",\"mmi\":null,\"cdi\":null,\"tz\":-420,\"felt\":null,\"nst\":10,\"dmin\":0.202,\"sig\":16,\"gap\":136.32},\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-118.6448,38.2705,3.48]}},{\"id\":\"nn00448587\",\"properties\":{\"detail\":\"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/nn00448587.geojson\",\"type\":\"earthquake\",\"net\":\"nn\",\"tsunami\":null,\"sources\":\",nn,\",\"title\":\"M 1.7 - 30km NNW of Hawthorne, Nevada\",\"time\":1402338781730,\"updated\":1402338918000,\"mag\":1.66,\"place\":\"30km NNW of Hawthorne, Nevada\",\"types\":\",general-link,geoserve,nearby-cities,origin,phase-data,\",\"status\":\"automatic\",\"alert\":null,\"ids\":\",nn00448587,\",\"rms\":null,\"code\":\"00448587\",\"url\":\"http://earthquake.usgs.gov/earthquakes/eventpage/nn00448587\",\"magType\":\"ml\",\"mmi\":null,\"cdi\":null,\"tz\":-420,\"felt\":null,\"nst\":14,\"dmin\":0.252,\"sig\":42,\"gap\":86.71},\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-118.8028,38.7582,5.89]}},{\"id\":\"nc72235041\",\"properties\":{\"detail\":\"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/nc72235041.geojson\",\"type\":\"earthquake\",\"net\":\"nc\",\"tsunami\":null,\"sources\":\",nc,\",\"title\":\"M 2.4 - 30km SE of Yosemite Valley, California\",\"time\":1402338284640,\"updated\":1402339508232,\"mag\":2.38,\"place\":\"30km SE of Yosemite Valley, California\",\"types\":\",general-link,geoserve,nearby-cities,origin,phase-data,scitech-link,\",\"status\":\"automatic\",\"alert\":null,\"ids\":\",nc72235041,\",\"rms\":0.06,\"code\":\"72235041\",\"url\":\"http://earthquake.usgs.gov/earthquakes/eventpage/nc72235041\",\"magType\":\"md\",\"mmi\":null,\"cdi\":null,\"tz\":-420,\"felt\":null,\"nst\":4,\"dmin\":0.2887,\"sig\":87,\"gap\":152},\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-119.3801651,37.515667,5.02]}},{\"id\":\"nc72235036\",\"properties\":{\"detail\":\"http://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/nc72235036.geojson\",\"type\":\"earthquake\",\"net\":\"nc\",\"tsunami\":null,\"sources\":\",nc,\",\"title\":\"M 0.8 - 3km NNW of The Geysers, California\",\"time\":1402337385500,\"updated\":1402338488132,\"mag\":0.8,\"place\":\"3km NNW of The Geysers, California\",\"types\":\",general-link,geoserve,nearby-cities,origin,phase-data,scitech-link,\",\"status\":\"AUTOMATIC\",\"alert\":null,\"ids\":\",nc72235036,\",\"rms\":0.02,\"code\":\"72235036\",\"url\":\"http://earthquake.usgs.gov/earthquakes/eventpage/nc72235036\",\"magType\":\"Md\",\"mmi\":null,\"cdi\":null,\"tz\":-420,\"felt\":null,\"nst\":9,\"dmin\":0.01796631,\"sig\":10,\"gap\":90},\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[-122.7715,38.8033,2.3]}}],\"type\":\"FeatureCollection\",\"metadata\":{\"title\":\"USGS All Earthquakes, Past Hour\",\"count\":9,\"status\":200,\"generated\":1402340784000,\"api\":\"1.0.13\",\"url\":\"http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.geojson\"}}";
        return debugBody;
    }

    @Override
    protected String getHostName() {
        return "earthquake.usgs.gov";
    }

    @Override
    protected int getPort() {
        return 80;
    }

    @Override
    protected String getProtocol() {
        return "http";
    }

    @Override
    protected String getProviderClassName() {
        return ProviderConnector_JSON.class.getName();
    }

    @Override
    public String getProviderName() {
        return "USGSEarthQuake";
    }

    @Override
    protected String getQuery() {
        return "/earthquakes/feed/v1.0/summary/all_hour.geojson";
    }

    @Override
    public Map<String, String> getRequestHeaders() {
        return null;
    }

    @Override
    public void setQuery(final String query) {
        super._query = query;
    }

    @Override
    protected Object translateDataPoint(final Object name, final Object value) {
        if (name.equals(Key.LOCATION_FULL) && value instanceof List<?>) {
            super.map.put(Key.LOCATION_FULL, (List<Map<String, Object>>) value);
        }
        return value;
    }

    @Override
    protected void translateFinal() {
        // for (final Object o : arryList) {
        // if (o instanceof HashMap) {
        // final HashMap<String, Object> hashMap = (HashMap<String, Object>) o;
        // for (final Entry<String, Object> entry : hashMap.entrySet()) {
        // CallerId.identifyMessage(entry.getValue().getClass().getSimpleName() + " " + entry.getKey() + " " + entry.getValue());
        // }
        // }
        // }
    }

    @Override
    protected void translateQuery() {
    }
}
